package operation;

import book.Book;
import book.BookList;

import java.util.Scanner;

public class AddOperation implements IOPeration{
    @Override
    public void work(BookList bookList) {
        System.out.println("新增图书");
        Scanner scanner = new Scanner(System.in);
        System.out.println("输入书名");
        String name = scanner.nextLine();
        System.out.println("输入作者姓名");
        String author = scanner.nextLine();
        System.out.println("输入书的价格");
        int price = scanner.nextInt();
        scanner.nextLine();
        System.out.println("输入书的类型");
        String type = scanner.nextLine();
        Book book = new Book(name,author,price,type);
        int size = bookList.getUsedSize();
        for(int i = 0;i < size; i++){
            Book book1 = bookList.getBook(i);
            if(book1.getName().equals(name)){
                System.out.println("你添加的用户已经存在！");
                return;
            }
        }
        bookList.setBooks(size,book);
        bookList.setUsedSize(size+1);
    }
}
